package com.song.study.spring.Entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @Author ZhangGuisong
 * @Date 2021/4/24-16:05
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Dog implements Condition {
    private String name;

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        Environment environment = context.getEnvironment();
        if(environment.containsProperty("animal.name")){
            return true;
        }
        return false;
    }
}
